#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System.Collections.Generic;
using System.Text;

namespace Neatly.UI
{
    public static class UIStringBuilder
    {
        private const int CACHE_COUNT = 100;
        private static List<StringBuilder> m_Queue = new List<StringBuilder>();

        public static StringBuilder Create()
        {
            if (m_Queue.Count > 0)
            {
                var cache = m_Queue[0];
                m_Queue.RemoveAt(0);
                cache.Length = 0;
                return cache;
            }
            return new StringBuilder();
        }

        public static string GetStringAndRelease(StringBuilder sb)
        {
            string str = sb.ToString();
            Release(sb);
            return str;
        }

        public static void Release(StringBuilder sb)
        {
            if (m_Queue.Count >= CACHE_COUNT) return;
            sb.Length = 0;
            m_Queue.Add(sb);
        }
    }
}
